﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace XDA_ROM_Hub
{
    public partial class StockRom : Form
    {
        public StockRom()
        {
            InitializeComponent();
            UserClosing = false;
            this.buttonExit.Click += new EventHandler(buttonExit_Click);
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        
        }

        private void StockRomNoob_Load(object sender, EventArgs e)
        {
            if (File.Exists(@"c:\Flashtool\Flashtool.exe"))
            {
                checkBox1.Checked = true;
            }

            label2.Text = Properties.Settings.Default.SelectedDevice;
            this.mini.Visible = false;
            this.minipro.Visible = false;
            this.miniproa.Visible = false;
            this.active.Visible = false;
            this.lww.Visible = false;
            this.ray.Visible = false;
            this.arc.Visible = false;
            this.arcs.Visible = false;
            this.neo.Visible = false;
            this.neov.Visible = false;
            this.play.Visible = false;
            this.lwwa.Visible = false;
            this.pro.Visible = false;
this.activea.Visible = false;

            if (this.label2.Text.Contains("(ST15i)"))
            {
                this.mini.Visible = true;
            }
            if (this.label2.Text.Contains("(ST17a)"))
            {
                this.activea.Visible = true;
            }
            if (this.label2.Text.Contains("(MK16i)"))
            {
                this.pro.Visible = true;
            }
            if (this.label2.Text.Contains("(WT19a)"))
            {
                this.lwwa.Visible = true;
            }
            if (this.label2.Text.Contains("(SK17i)"))
            {
                this.minipro.Visible = true;
            }
            if (this.label2.Text.Contains("(ST17a)"))
            {
                this.miniproa.Visible = true;
            } if (this.label2.Text.Contains("(ST17i)"))
            {
                this.active.Visible = true;
            } if (this.label2.Text.Contains("(WT19i)"))
            {
                this.lww.Visible = true;
            } if (this.label2.Text.Contains("(ST18i)"))
            {
                this.ray.Visible = true;
            } if (this.label2.Text.Contains("(LT15i)"))
            {
                this.arc.Visible = true;
            } if (this.label2.Text.Contains("(LT18i)"))
            {
                this.arcs.Visible = true;
            } if (this.label2.Text.Contains("(MT15i)"))
            {
                this.neo.Visible = true;
            } if (this.label2.Text.Contains("(MT11i)"))
            {
                this.neov.Visible = true;
            } if (this.label2.Text.Contains("(R800i)"))
            {
                this.play.Visible = true;
            }


        }

        public bool UserClosing { get; set; }

        void buttonExit_Click(object sender, EventArgs e)
        {
            UserClosing = true;
            cencelbtn();
        }

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            switch (e.CloseReason)
            {
                case CloseReason.ApplicationExitCall:
                    break;
                case CloseReason.FormOwnerClosing:
                    break;
                case CloseReason.MdiFormClosing:
                    break;
                case CloseReason.None:
                    break;
                case CloseReason.TaskManagerClosing:
                    break;
                case CloseReason.UserClosing:
                    if (UserClosing)
                    {
                        cencelbtn();
                    }
                    else
                    {
                        cencelbtn();
                    }
                    break;
                case CloseReason.WindowsShutDown:
                    break;
                default:
                    break;
            }
        }

        public void cencelbtn()
        {
        	this.Hide();

        }
        private void button1_Click(object sender, EventArgs e)
        {
            string URL = this.Text;
            string URLgood = URL.Replace(" ", "%20");

            if (checkBox1.Checked == false)
            {
                InstallFlashtool instft = new InstallFlashtool();
                instft.Show();
                this.Hide();
            }
            else
            {
            	MessageBox.Show("If you get errors, the firmware you are trying to download is not available yet.\nIf so, try again later.", "", MessageBoxButtons.OK, MessageBoxIcon.Information,MessageBoxDefaultButton.Button1);
                progress prog = new progress();
                prog.Text = this.Text;
                prog.txtUrl.Text = "http://xperiaromhub.fav.cc/firmwares/" + URLgood + ".zip";
                prog.txtPath.Text = prog.txtPath.Text + this.Text + ".zip";
                prog.Show();

                this.Hide();
            }
        }

        private void play_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + play.SelectedItem;
        }

        private void mini_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + mini.SelectedItem;
        }

        private void minipro_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + minipro.SelectedItem;
        }

        private void miniproa_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + miniproa.SelectedItem;
        }

        private void active_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + active.SelectedItem;
        }

        private void lww_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + lww.SelectedItem;
        }

        private void ray_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + ray.SelectedItem;
        }

        private void arc_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + arc.SelectedItem;
        }

        private void arcs_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + arcs.SelectedItem;
        }

        private void neo_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + neo.SelectedItem;
        }

        private void neov_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + neov.SelectedItem;
        }


        private void lwwa_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + lwwa.SelectedItem;
        }

        private void pro_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = label2.Text;
            this.Text = this.Text + pro.SelectedItem;
        }

        private void activea_SelectedIndexChanged(object sender, EventArgs e)
        {
this.Text = label2.Text;
            this.Text = this.Text + activea.SelectedItem;
        }
    }
}
